package com.dr.web.controllers;

import com.dr.common.pojo.WeChatOpenid;
import com.dr.common.ution.StringUtil;
import com.dr.common.ution.WeChatUtil;
import com.dr.pojo.Student;
import com.dr.service.StudentInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * Created by tugou on 2017/4/25.
 * 报名界面controller
 */
@Controller
@RequestMapping("student")
public class SignUpController {

    @Autowired
    StudentInfoService studentInfoService;


    static Logger logger =  Logger.getLogger(SignUpController.class);
    /**
     * 微信报名页面
     * @param session
     * @param code
     * @return
     */
    @RequestMapping(value="sign",method= RequestMethod.GET)
    public String signUp(HttpSession session, String code){
        if (StringUtil.isNotEmpty(code)){
            WeChatOpenid content =  WeChatUtil.getWeChatOpenid(code);
            String openId = content.getOpenid();
            logger.info("获取Openid："+openId+"||"+ new Date());
            session.setAttribute("openId",openId);
            Student student = studentInfoService.getStudent(openId);
            if (student == null){
                return "/wechat/register";
            }
            if (student.getBespeak() == 1){

            }
            if (student.getBespeak() == 2){

            }
        }
        else{

        }
        return null;
    }
}
